package com.szty.libarytest.other

import android.bluetooth.BluetoothManager
import android.content.Context
import android.content.Intent
import android.location.LocationManager
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.provider.Settings
import android.text.TextPaint
import android.text.style.ClickableSpan
import android.view.View
import com.blankj.utilcode.util.SpanUtils
import com.szty.libarytest.R
import kotlinx.android.synthetic.main.activity_g_p_s_service.*

class GPSServiceActivity : AppCompatActivity() {
    val manager by lazy {
        getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager
    }
    val mBluetoothAdapter = manager.adapter

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_g_p_s_service)
        btn_open.setOnClickListener {
            val intent = Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)
            startActivityForResult(intent,102)
        }
        btn_scan.setOnClickListener {
            mBluetoothAdapter.bluetoothLeScanner.startScan(null,)

            tv_show_info.text =
                SpanUtils().append("请打开").append("定位服务").setClickSpan(object : ClickableSpan() {
                    override fun onClick(widget: View) {
                        "点击了文本".loge()
                    }

                    override fun updateDrawState(ds: TextPaint) {
                        super.updateDrawState(ds)
                        ds.color = ds.linkColor
                    }
                }).create()

        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if(requestCode == 102){
            val systemService = getSystemService(Context.LOCATION_SERVICE) as LocationManager
        if(systemService.isProviderEnabled(LocationManager.GPS_PROVIDER)){
            "成功打开定位服务".loge()
        }else{
            "打开定位服务失败".loge()
        }
        }
    }
}